From 2e2cd8b272d00749055c615bfa013c39771f8428 Mon Sep 17 00:00:00 2001 From: "cwc22@centipede.cl.cam.ac.uk" Date: Tue, 5 Apr 2005 00:55:55 +0000 Subject: [PATCH] bitkeeper revision 1.1236.1.213 (4251e21boiMcVvsOm7kHtd1O51o1mA) Dynamic sizing of a domain's grant map tracking table on demand. Grant tables now default for block front/back communication. --- .../arch/xen/defconfig-xen0 | 2 +- .../arch/xen/defconfig-xenU | 2 +- linux-2.6.11-xen-sparse/arch/xen/Kconfig | 5 +-- xen/common/grant_table.c | 44 ++++++++++++++----- xen/include/xen/grant_table.h | 3 +- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/linux-2.4.29-xen-sparse/arch/xen/defconfig-xen0 b/linux-2.4.29-xen-sparse/arch/xen/defconfig-xen0 index b67e52aff6..3e0014cf5e 100644 --- a/linux-2.4.29-xen-sparse/arch/xen/defconfig-xen0 +++ b/linux-2.4.29-xen-sparse/arch/xen/defconfig-xen0 @@ -16,7 +16,7 @@ CONFIG_XEN_PHYSDEV_ACCESS=y CONFIG_XEN_SCRUB_PAGES=y CONFIG_XEN_NETDEV_FRONTEND=y CONFIG_XEN_BLKDEV_FRONTEND=y -# CONFIG_XEN_BLKDEV_GRANT is not set +CONFIG_XEN_BLKDEV_GRANT=y # CONFIG_XEN_USB_FRONTEND is not set CONFIG_NO_IDLE_HZ=y CONFIG_FOREIGN_PAGES=y diff --git a/linux-2.4.29-xen-sparse/arch/xen/defconfig-xenU b/linux-2.4.29-xen-sparse/arch/xen/defconfig-xenU index a83c1b8392..61db0a1b65 100644 --- a/linux-2.4.29-xen-sparse/arch/xen/defconfig-xenU +++ b/linux-2.4.29-xen-sparse/arch/xen/defconfig-xenU @@ -15,7 +15,7 @@ CONFIG_UID16=y CONFIG_XEN_SCRUB_PAGES=y CONFIG_XEN_NETDEV_FRONTEND=y CONFIG_XEN_BLKDEV_FRONTEND=y -# CONFIG_XEN_BLKDEV_GRANT is not set +CONFIG_XEN_BLKDEV_GRANT=y # CONFIG_XEN_USB_FRONTEND is not set CONFIG_NO_IDLE_HZ=y # CONFIG_FOREIGN_PAGES is not set diff --git a/linux-2.6.11-xen-sparse/arch/xen/Kconfig b/linux-2.6.11-xen-sparse/arch/xen/Kconfig index 9a753a6bf9..8205344169 100644 --- a/linux-2.6.11-xen-sparse/arch/xen/Kconfig +++ b/linux-2.6.11-xen-sparse/arch/xen/Kconfig @@ -64,12 +64,11 @@ config XEN_BLKDEV_TAP_BE config XEN_BLKDEV_GRANT bool "Grant table substrate for block drivers (DANGEROUS)" depends on !XEN_BLKDEV_TAP_BE - default n + default y help This introduces the use of grant tables as a data exhange mechanism between the frontend and backend block drivers. This currently - conflicts with the block tap, and should be considered untested - and likely to render your system unstable. + conflicts with the block tap. config XEN_NETDEV_BACKEND bool "Network-device backend driver" diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 446783c48e..c78720022f 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -42,7 +42,7 @@ get_maptrack_handle( grant_table_t *t) { unsigned int h; - if ( unlikely((h = t->maptrack_head) == NR_MAPTRACK_ENTRIES) ) + if ( unlikely((h = t->maptrack_head) == t->maptrack_limit) ) return -1; t->maptrack_head = t->maptrack[h].ref_and_flags >> MAPTRACK_REF_SHIFT; t->map_count++; @@ -362,10 +362,30 @@ __gnttab_map_grant_ref( /* get a maptrack handle */ if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) ) { - put_domain(rd); - DPRINTK("No more map handles available\n"); - (void)__put_user(GNTST_no_device_space, &uop->handle); - return GNTST_no_device_space; + int i; + grant_mapping_t *new_mt; + grant_table_t *lgt = ld->grant_table; + + /* grow the maptrack table */ + if ( (new_mt = (void *)alloc_xenheap_pages(lgt->maptrack_order + 1)) == NULL ) + { + put_domain(rd); + DPRINTK("No more map handles available\n"); + (void)__put_user(GNTST_no_device_space, &uop->handle); + return GNTST_no_device_space; + } + + memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order); + for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ ) + new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT; + + free_xenheap_pages((unsigned long)lgt->maptrack, lgt->maptrack_order); + lgt->maptrack = new_mt; + lgt->maptrack_order += 1; + lgt->maptrack_limit <<= 1; + + printk("Doubled maptrack size\n"); + handle = get_maptrack_handle(ld->grant_table); } #ifdef GRANT_DEBUG_VERBOSE @@ -458,7 +478,7 @@ __gnttab_unmap_grant_ref( map = &ld->grant_table->maptrack[handle]; - if ( unlikely(handle >= NR_MAPTRACK_ENTRIES) || + if ( unlikely(handle >= ld->grant_table->maptrack_limit) || unlikely(!(map->ref_and_flags & MAPTRACK_GNTMAP_MASK)) ) { DPRINTK("Bad handle (%d).\n", handle); @@ -752,7 +772,7 @@ gnttab_dump_table(gnttab_dump_table_t *uop) } } - for ( i = 0; i < NR_MAPTRACK_ENTRIES; i++ ) + for ( i = 0; i < gt->maptrack_limit; i++ ) { maptrack = >->maptrack[i]; @@ -860,7 +880,7 @@ gnttab_check_unmap( rgt = rd->grant_table; - for ( handle = 0; handle < NR_MAPTRACK_ENTRIES; handle++ ) + for ( handle = 0; handle < lgt->maptrack_limit; handle++ ) { map = &lgt->maptrack[handle]; @@ -1074,8 +1094,10 @@ grant_table_create( /* Tracking of mapped foreign frames table */ if ( (t->maptrack = (void *)alloc_xenheap_page()) == NULL ) goto no_mem; + t->maptrack_order = 0; + t->maptrack_limit = PAGE_SIZE / sizeof(grant_mapping_t); memset(t->maptrack, 0, PAGE_SIZE); - for ( i = 0; i < NR_MAPTRACK_ENTRIES; i++ ) + for ( i = 0; i < t->maptrack_limit; i++ ) t->maptrack[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT; /* Shared grant table. */ @@ -1121,7 +1143,7 @@ gnttab_release_dev_mappings(grant_table_t *gt) ld = current->domain; - for ( handle = 0; handle < NR_MAPTRACK_ENTRIES; handle++ ) + for ( handle = 0; handle < gt->maptrack_limit; handle++ ) { map = >->maptrack[handle]; @@ -1191,7 +1213,7 @@ grant_table_destroy( /* Free memory relating to this grant table. */ d->grant_table = NULL; free_xenheap_pages((unsigned long)t->shared, ORDER_GRANT_FRAMES); - free_xenheap_page((unsigned long)t->maptrack); + free_xenheap_page((unsigned long)t->maptrack); //cwc22 xfree(t->active); xfree(t); } diff --git a/xen/include/xen/grant_table.h b/xen/include/xen/grant_table.h index f37d6d4e56..c273eacada 100644 --- a/xen/include/xen/grant_table.h +++ b/xen/include/xen/grant_table.h @@ -66,7 +66,6 @@ typedef struct { } grant_mapping_t; #define MAPTRACK_GNTMAP_MASK 7 #define MAPTRACK_REF_SHIFT 3 -#define NR_MAPTRACK_ENTRIES (PAGE_SIZE / sizeof(grant_mapping_t)) /* Per-domain grant information. */ typedef struct { @@ -77,6 +76,8 @@ typedef struct { /* Mapping tracking table. */ grant_mapping_t *maptrack; unsigned int maptrack_head; + unsigned int maptrack_order; + unsigned int maptrack_limit; unsigned int map_count; /* Lock protecting updates to active and shared grant tables. */ spinlock_t lock; -- 2.30.2